<?php

/*
  Plugin Name: Embed iPhone/iPad App
  Plugin URI: http://wordpress.org/extend/plugins/embed-iphoneipad-app
  Description: Convert iTunes App Store Link To App Info HTML
  Author: Roomshare Japan
  Version: 1.5.0
  Author URI: http://roomshare.jp/
  License: GPL2
 */

/*
  Copyright (c) 2011 Roomshare Japan

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

// duplication of codes, as too old environment can not even load my classes
add_action('admin_notices', 'eia_check_environment');
function eia_check_environment() {
    if (version_compare( PHP_VERSION, '5.3', '<' )) {
        echo '<p>';
        echo 'Embed iPhone/iPad App' . ' requires PHP verion ' . '5.3' . ' or newer';
        echo ', but yours is ' . PHP_VERSION . '. ';
        echo 'The plugin has been deactivated.';
        echo '</p>';
        require_once ABSPATH . '/wp-admin/includes/plugin.php';
        deactivate_plugins( __FILE__ );
        exit();
    }
    global $wp_version;
    if (version_compare( $wp_version, '3.3', '<' )) {
        echo '<p>';
        echo 'Embed iPhone/iPad App' . ' requires WordPress verion ' . '3.3' . ' or newer';
        echo ', but yours is ' . PHP_VERSION . '. ';
        echo 'The plugin has been deactivated.';
        echo '</p>';
        require_once ABSPATH . '/wp-admin/includes/plugin.php';
        deactivate_plugins( __FILE__ );
        exit();
    }
}

// if you install Zend Framework 1 by Composer, this will autoload it
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
  // read external libraries (Zend Framework 1.x for Zend_Locale)
  require_once realpath( __DIR__ . '/vendor/autoload.php' );
}

function rsj_autoload($className)
{
    // a class using class_exists() collides with WP so limits loaded classes
    if (strncasecmp($className, 'Rsj_', 4) !== 0) {
        return false;
    }
    $className = ltrim($className, '\\');
    $fileName  = '';
    $namespace = '';
    if ($lastNsPos = strripos($className, '\\')) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

    require 'includes/' . $fileName;
}
spl_autoload_register('rsj_autoload');

if (defined('EIA_IN_PHPUNIT_TEST')) { // see tests/bootstrap.php
  $GLOBALS[Rsj_EmbedIphoneIpadApp::PLUGIN_KEY] = new Rsj_EmbedIphoneIpadApp();
} else {
  new Rsj_EmbedIphoneIpadApp();
}
